/*---------------------------------------------------------*/
/*           JSC YMC13265-07A 测试程序                     */
/*---------------------------------------------------------*/
/*---------------------------------------------------------*/
/*---------------------------------------------------------*/
/*修改记录在案 :根据客户新提供的初始化修改程序             */
/*---------------------------------------------------------*/
/*   时间            人员            修改项目              */
/*2013.02.16           LH             开始编制             */
//2015.10.28		  grr			  增加自动断电部分，其他不变
/*---------------------------------------------------------*/
/*---------------------IC:SPLC502B ------------------------*/
// VDD=3.3V ,VLCD=7.7V,1/55Duty,1/6bias
/*---------------------------------------------------------*/
#include "STC89xx.h"
//#include <intrins.h>
#include <ctype.h>
#include <stdint.h>
#include "delay.h"
#include "uart.h"

/*----------------------------------------------------------*/
/*     定义 CPU  PORT                             */
/*----------------------------------------------------------*/
#define PORT P1
#define CS P20
#define RESET P21
#define RS P22
#define WR P23
#define RD P24
#define stop P40
#define VDD P41
#define VLED P43
#define key P43

/*-------------------------------------------------------------*/
uint16_t page1, column1;
uint16_t wait;
/*-------------------------------------------------------------*/
/*定义延迟时间常数                                             */
/*-------------------------------------------------------------*/
#define EEDLY 8
#define DSDLY 5
#define CMDLY 200
#define Delay() \
    _nop_();    \
    _nop_();    \
    _nop_();    \
    _nop_()
void delay(uint16_t t)
{
    wait = t;
    do
    {
        --wait;
    } while (wait);
} /*t=1 17.6us*/
//void busy() { delay(50); }
/*-------------------------------------------------------------*/
/*涵数原形定义                                                 */
/*-------------------------------------------------------------*/

void C13265_07_init(void);
void C13265_07_full(void);
void C13265_07_clear(void);
void C13265_07_img1(void);
void C13265_07_img2(void);
void C13265_07_img3(void);
void C13265_07_img4(void);
void _C13265_07_goToOrigin(void);
/*-------------------------------------------------------------*/
/*------------------------IMAGE DATA---------------------------*/
const uint8_t IMAGE0[] = {/*--  调入了一幅图像：d:\My Documents\桌面\Co0157A\12856A.bmp  --*/
                          /*--  调入了一幅图像：d:\My Documents\桌面\13265A.bmp  --*/
                          /*--  宽度x高度=132x65  --*/
                          /*--  高度不是8的倍数，现调整为：宽度x高度=132x72  --*/
                          0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x11, 0xF1, 0x11, 0x01, 0x11, 0xF1, 0x11, 0x01,
                          0x81, 0x81, 0x91, 0x01, 0x01, 0x01, 0x01, 0x01, 0x81, 0x81, 0x81, 0x81, 0x01, 0x81, 0x81, 0xE1,
                          0x81, 0x81, 0x01, 0x01, 0x01, 0x81, 0x81, 0x01, 0x81, 0x81, 0x01, 0x01, 0x01, 0x81, 0x81, 0x81,
                          0x01, 0x01, 0x81, 0x81, 0x81, 0x01, 0x81, 0x81, 0x81, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
                          0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
                          0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x31, 0x11, 0x11, 0xF1, 0x11, 0x01, 0x11, 0xF1, 0x11, 0x01,
                          0x01, 0x01, 0x01, 0x01, 0x01, 0x21, 0xF1, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
                          0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
                          0x01, 0x01, 0x01, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x1F, 0x11, 0x01,
                          0x11, 0x1F, 0x10, 0x00, 0x10, 0x10, 0x1F, 0x10, 0x10, 0x00, 0x00, 0x19, 0x12, 0x12, 0x14, 0x09,
                          0x00, 0x00, 0x00, 0x0F, 0x10, 0x10, 0x00, 0x00, 0x00, 0x10, 0x1F, 0x11, 0x10, 0x00, 0x00, 0x00,
                          0x0F, 0x10, 0x10, 0x10, 0x0F, 0x00, 0x40, 0x41, 0x66, 0x18, 0x06, 0x01, 0x00, 0x00, 0x00, 0x00,
                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00,
                          0x10, 0x1F, 0x10, 0x10, 0x10, 0x18, 0x00, 0x00, 0x00, 0x10, 0x1F, 0x10, 0x00, 0x00, 0x00, 0x00,
                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x01, 0x01, 0x01, 0xF1, 0x09, 0x09, 0x09,
                          0xF1, 0x01, 0x01, 0x01, 0x11, 0xF9, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
                          0x09, 0xF9, 0x49, 0x49, 0x49, 0xB1, 0x01, 0x01, 0x81, 0x41, 0x41, 0x41, 0x81, 0x01, 0x41, 0x41,
                          0xF1, 0x41, 0x41, 0x01, 0x01, 0x41, 0x41, 0xF1, 0x41, 0x41, 0x01, 0x01, 0x01, 0x81, 0x41, 0x41,
                          0x41, 0x81, 0x01, 0x01, 0x41, 0xC1, 0x81, 0x41, 0x41, 0x01, 0x41, 0xC1, 0x41, 0x01, 0x41, 0xC1,
                          0x41, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0xE1, 0x19, 0xE1, 0x01, 0x01, 0x09,
                          0xF9, 0x41, 0x41, 0x41, 0x81, 0x01, 0x01, 0x81, 0x41, 0x41, 0x41, 0xC1, 0x01, 0x01, 0x81, 0x41,
                          0x41, 0x41, 0x81, 0x01, 0x41, 0xC1, 0x81, 0x41, 0x41, 0x81, 0x01, 0x41, 0x41, 0xF1, 0x41, 0x41,
                          0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0xFF, 0xFF, 0x00, 0x00, 0x00,
                          0x07, 0x08, 0x08, 0x08, 0x07, 0x00, 0x00, 0x00, 0x08, 0x0F, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
                          0x00, 0x00, 0x00, 0x00, 0x08, 0x0F, 0x08, 0x08, 0x08, 0x07, 0x00, 0x00, 0x04, 0x0A, 0x09, 0x09,
                          0x0F, 0x08, 0x00, 0x00, 0x07, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x07, 0x08, 0x08, 0x00, 0x00,
                          0x00, 0x07, 0x09, 0x09, 0x09, 0x05, 0x00, 0x00, 0x08, 0x0F, 0x08, 0x08, 0x00, 0x00, 0x20, 0x20,
                          0x33, 0x0C, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x0E, 0x09, 0x01,
                          0x09, 0x0E, 0x08, 0x00, 0x0F, 0x08, 0x08, 0x08, 0x07, 0x00, 0x00, 0x0C, 0x09, 0x09, 0x0A, 0x04,
                          0x00, 0x00, 0x07, 0x09, 0x09, 0x09, 0x05, 0x00, 0x08, 0x0F, 0x08, 0x00, 0x00, 0x0F, 0x08, 0x00,
                          0x00, 0x07, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF,
                          0xFF, 0x00, 0x00, 0x00, 0xFE, 0x01, 0x01, 0x01, 0xFE, 0x00, 0x00, 0x86, 0x41, 0x21, 0x11, 0x0E,
                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0x09, 0x09, 0x09, 0xF6, 0x00, 0x00,
                          0x90, 0x48, 0x28, 0x28, 0xF0, 0x00, 0x08, 0x08, 0xFE, 0x08, 0x08, 0x00, 0x00, 0x08, 0x08, 0xFE,
                          0x08, 0x08, 0x00, 0x00, 0x00, 0xF0, 0x28, 0x28, 0x28, 0xB0, 0x00, 0x00, 0x08, 0xF8, 0x10, 0x08,
                          0x08, 0x00, 0x08, 0x18, 0x68, 0x80, 0x68, 0x18, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                          0x00, 0xC0, 0x3C, 0x23, 0x3C, 0xC0, 0x00, 0x01, 0xFF, 0x08, 0x08, 0x08, 0xF0, 0x00, 0x00, 0x90,
                          0x28, 0x28, 0x48, 0x98, 0x00, 0x00, 0xF0, 0x28, 0x28, 0x28, 0xB0, 0x00, 0x08, 0xF8, 0x10, 0x08,
                          0x08, 0xF0, 0x00, 0x08, 0x08, 0xFE, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                          0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x80, 0x41, 0x41, 0x41, 0x80, 0x00, 0x00, 0x81,
                          0x41, 0x41, 0x41, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x81, 0x41, 0x41,
                          0x81, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00,
                          0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00,
                          0x81, 0x41, 0x41, 0x41, 0x80, 0x00, 0x04, 0x84, 0x46, 0x41, 0x40, 0x80, 0x00, 0x00, 0x00, 0x80,
                          0xC0, 0x00, 0x00, 0x00, 0x01, 0x81, 0x41, 0x40, 0x41, 0x81, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01,
                          0x00, 0x00, 0x00, 0x81, 0x41, 0x41, 0x41, 0x80, 0x00, 0x00, 0xC0, 0x41, 0x41, 0x41, 0x40, 0x00,
                          0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x80, 0x40, 0x41, 0x41, 0x80, 0x00, 0x00, 0x00,
                          0x80, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x3F, 0x40, 0x40, 0x40,
                          0x3F, 0x00, 0x00, 0x20, 0x40, 0x42, 0x42, 0x3D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                          0x1F, 0x20, 0x40, 0x40, 0x20, 0x1F, 0x00, 0x02, 0xFE, 0x42, 0x42, 0x42, 0x3C, 0x00, 0x00, 0x3C,
                          0x4A, 0x4A, 0x4A, 0x2C, 0x00, 0x42, 0x7E, 0x44, 0x02, 0x02, 0x7C, 0x40, 0x00, 0x00, 0x00, 0x00,
                          0x00, 0x00, 0x00, 0x00, 0x61, 0x50, 0x48, 0x44, 0x43, 0x00, 0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F,
                          0x00, 0x00, 0x00, 0x40, 0x7F, 0x40, 0x00, 0x00, 0x00, 0x61, 0x50, 0x48, 0x44, 0x43, 0x00, 0x04,
                          0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F, 0x00, 0x00, 0x37, 0x42,
                          0x42, 0x42, 0x3C, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x20, 0x40, 0x42, 0x42,
                          0x3D, 0x00, 0x00, 0x00, 0x40, 0x7F, 0x40, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00,
                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00,
                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF,
                          0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
                          0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
                          0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
                          0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
                          0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
                          0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
                          0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
                          0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
                          0xFF, 0xFF, 0xFF, 0xFF

};

/*-------------------------------------------------------------*/
/*---------------- WRITE COMMAND PROGRAM ----------------------*/

void setcom(uint8_t par)
{
    //busy_flag();

    RS = 0;
    _nop_();
    _nop_();
    RD = 1;
    _nop_();
    _nop_();
    WR = 0;
    _nop_();
    _nop_();
    PORT = par;
    _nop_();
    _nop_();
    RD = 1;
    _nop_();
    _nop_();
    WR = 1;
    _nop_();
    _nop_();
    RS = 1;
    _nop_();
    _nop_();
    _nop_();
    _nop_();
}

/*------------------------------------------------------------*/
/*-------------WRITE DISPLAY DATA PROGRAM----------------*/

void Write_uint8_tdata(uint8_t par)
{
    //busy_flag();
    _nop_();
    _nop_();
    RS = 1;
    _nop_();
    _nop_();
    WR = 0;
    _nop_();
    _nop_();
    RD = 1;
    _nop_();
    _nop_();
    PORT = par;
    _nop_();
    _nop_();
    RS = 1;
    _nop_();
    _nop_();
    WR = 1;
    _nop_();
    _nop_();
    RD = 1;
    _nop_();
    _nop_();
}

/*------------------------------------------------------------*/

void drawByte(uint8_t column, uint8_t page, uint8_t byteData)
{

}

void fill(uint8_t byteData)
{
    uint8_t page, column;
    _C13265_07_goToOrigin();

    for (page = 0xb0; page < 0xb9; page++)
    {
        setcom(page);
        setcom(0x10); /*set Y address*/
        setcom(0x00); /*set Y address*/
        for (column = 0; column < 132; column++)
        {
            Write_uint8_tdata(byteData);
        }
    }
}
void write_data(uint8_t *par)
{
    uint8_t page, column;
    setcom(0xaf); /*SET DISPLAY ON*/
    for (page = 0xb0; page < 0xb9; page++)
    {
        setcom(page);
        setcom(0x10); /*set Y address*/
        setcom(0x00); /*set Y address*/
        for (column = 0; column < 132; column++)
        {
            Write_uint8_tdata(*(par++));
        }
    }
}

/*----------------C13265_07_init PROGRAM---------------------------*/
void C13265_07_init()
{
    setcom(0xe2);
    // setcom(0xae);/*set display off*/
    setcom(0xa1); /*set ADC=1 */
    setcom(0xc0); /*set SHL=1 */
    setcom(0xa2); /*set BIAS 1/6 */
    setcom(0xE0);
    setcom(0x2C);

    setcom(0x2E);
    setcom(0x2f); /*set VC VF VR on*/
    delay(1000);
    setcom(0x24); /*SET (1+Ra/Rb)=6.0*/
    delay(200);
    setcom(0x81); /*SET a=63*/
    setcom(0x2c); //old 0x2d
    delay(200);
    setcom(0xD2);
    setcom(0x01);
    setcom(0x40);
    setcom(0xb0);
    setcom(0x10);
    setcom(0x00);
    setcom(0xD5);
    setcom(0x00);
    setcom(0xAD);
    setcom(0xFF);
    setcom(0xA6); /*SET DISPLAY NORMAL*/
    setcom(0xA4);
    setcom(0xAf);
    delay(2000);
}



/*--------------------------------------------------------------*/
/*----------------main program----------------------------------*/
//void main()
void test(void)
{
    uint8_t page, column;
    uint8_t xscroll, yscroll, seg;
    uint16_t num;

    VDD = 0;  //VDD ON
    VLED = 0; //VLED ON

    CS = 0;
    RESET = 0;
    delay(2000);
    RESET = 1;
    CS = 0;
    C13265_07_init();
    setcom(0xaf); /*SET DISPLAY ON*/
    setcom(0x40); /*SET INITAL LINE*/
    setcom(0xb0); /*SET X ADDRESS*/
    setcom(0x10); /*SET Y ADDRESS*/
    setcom(0x00);
    //setcom(0xaf);/*SET DISPLAY OFF*/
    delay(255);
    for (;;)
    {
        setcom(0xaf); /*SET DISPLAY ON*/
        setcom(0x40); /*SET INITAL LINE*/
        setcom(0xb0); /*SET X ADDRESS*/
        setcom(0x10); /*SET Y ADDRESS*/
        setcom(0x00);

        /*--------------------------------------------------*/
        /*-------------ENTIRE DISPLAY ON--------------------*/

        setcom(0xa5); /*entire  display on*/
        for (num = 0; num < 800; num++)
        {
            delay(125);
        }

        setcom(0xa4); /*entire display off ,normal display on*/

        /*--------------------------------------------------*/
        /*-----------------X SCROLL-------------------------*/

        fill(0x00);
        setcom(0x40);
        for (page = 0xb0; page < 0xb9; page++)
        {
            setcom(page);
            setcom(0x10); /*set Y address*/
            setcom(0x00); /*set Y address*/
            for (column = 0; column < 132; column++)
            {
                Write_uint8_tdata(0x88);
            }
        }

        for (num = 0; num < 500; num++)
        {
            delay(125);
        }
        for (xscroll = 0x40; xscroll < 0x44; xscroll++)
        {
            setcom(xscroll);
            for (num = 0; num < 800; num++)
            {
                delay(125);
            }
        }

        /*--------------------------------------------------*/
        /*----------------Y SCROLL---------------------------*/
        fill(0x00);
        setcom(0x40);
        for (yscroll = 0x00; yscroll < 0x04; yscroll++)
        {
            for (page = 0xb0; page < 0xb9; page++)
            {
                setcom(page);
                setcom(0x10);    /*set Y address*/
                setcom(yscroll); /*set Y address*/
                for (column = 0; column < 132; column++)
                {
                    if (column % 4 == 0)
                        Write_uint8_tdata(0xff);
                    else
                        Write_uint8_tdata(0x00);
                }
            }

            for (num = 0; num < 800; num++)
            {
                delay(125);
            }
            fill(0x00);
        }

        /*--------------DISPLAY IMAGE ON-------------------------*/

        setcom(0x40); /*SET INITAL LINE*/
        write_data(IMAGE0);

        for (num = 0; num < 900; num++)
        {
            delay(125);
        }
        fill(0x00);

        VDD = 1;
        VLED = 1;
    }
}

void aoi(void)
{
    uint8_t page, column;
    uint8_t xscroll, yscroll /*, seg*/;
    uint16_t num;

    VDD = 0;  //VDD ON
    VLED = 0; //VLED ON

    CS = 0;
    RESET = 0;
    delay(20);
    RESET = 1;
    CS = 0;
    for (;;)
    {
        C13265_07_init();
        setcom(0xaf); /*SET DISPLAY ON*/
        setcom(0x40); /*SET INITAL LINE*/
        setcom(0xb0); /*SET X ADDRESS*/
        setcom(0x10); /*SET Y ADDRESS*/
        setcom(0x00);
        //setcom(0xaf);/*SET DISPLAY OFF*/
        delay(255);

        setcom(0xaf); /*SET DISPLAY ON*/
        setcom(0x40); /*SET INITAL LINE*/
        setcom(0xb0); /*SET X ADDRESS*/
        setcom(0x10); /*SET Y ADDRESS*/
        setcom(0x00);

        /*SBUF = 0;
        SBUF = 0;
        key = 1;
        for(;;){
            key = 1;
            delayms(1);

            if(key == 0){
                delayms(25);
                if(key == 0) {
                    while (key == 0);
                    delayms(5);
                
                    //SBUF = 0xFF;
                    //UartSend("press\r\n");
                    //UartSendByte (0xFF);
                    UartSendByte (0x3F);
                }
            }
            
        }*/

        /*--------------------------------------------------*/
        /*-------------ENTIRE DISPLAY ON--------------------*/

        /*setcom(0xa5); //entire  display on
        for (num = 0; num < 800; num++)
        {
            delay(125);
        }

        setcom(0xa4);//entire display off ,normal display on
        */
        
        setcom(0xa4);
        C13265_07_full();
        delayms(1000);
        /*--------------------------------------------------*/
        /*fill(0x33);
        delayms(1000);

        fill(0xCC);
        delayms(1000);

        fill(0x88);
        delayms(250);
        fill(0x44);
        delayms(250);
        fill(0x22);
        delayms(250);
        fill(0x11);
        delayms(250);*/
        C13265_07_img1();
        delayms(1000);
        C13265_07_img2();
        delayms(1000);
        C13265_07_img3();
        delayms(1000);
        C13265_07_img4();
        delayms(1000);

        /*setcom(0x40);
        for (page = 0xb0; page < 0xb9; page++)
        {
            setcom(page);
            setcom(0x10); //set Y address
            setcom(0x00); //set Y address
            for (column = 0; column < 132; column++)
            {
                Write_uint8_tdata(0x88);
            }
        }*/
        /*
        fill(0x88);

        for (num = 0; num < 500; num++)
        {
            delay(125);
        }
        for (xscroll = 0x40; xscroll < 0x44; xscroll++)
        {
            setcom(xscroll);
            for (num = 0; num < 800; num++)
            {
                delay(125);
            }
        }
        */

        _C13265_07_goToOrigin();

        for (page = 0xb0; page < 0xb9; page++)
        {
            setcom(page);
            setcom(0x10); /*set Y address*/
            setcom(0x00); /*set Y address*/
            for (column = 0; column < 132; column++)
            {
                if (column % 4 == 0)
                    Write_uint8_tdata(0xff);
                else
                    Write_uint8_tdata(0x00);
            }
        }
        delayms(1000);

                _C13265_07_goToOrigin();

        for (page = 0xb0; page < 0xb9; page++)
        {
            setcom(page);
            setcom(0x10); /*set Y address*/
            setcom(0x00); /*set Y address*/
            for (column = 0; column < 132; column++)
            {
                if (column % 4 == 1)
                    Write_uint8_tdata(0xff);
                else
                    Write_uint8_tdata(0x00);
            }
        }
        delayms(1000);

                _C13265_07_goToOrigin();

        for (page = 0xb0; page < 0xb9; page++)
        {
            setcom(page);
            setcom(0x10); /*set Y address*/
            setcom(0x00); /*set Y address*/
            for (column = 0; column < 132; column++)
            {
                if (column % 4 == 2)
                    Write_uint8_tdata(0xff);
                else
                    Write_uint8_tdata(0x00);
            }
        }
        delayms(1000);

                _C13265_07_goToOrigin();

        for (page = 0xb0; page < 0xb9; page++)
        {
            setcom(page);
            setcom(0x10); /*set Y address*/
            setcom(0x00); /*set Y address*/
            for (column = 0; column < 132; column++)
            {
                if (column % 4 == 3)
                    Write_uint8_tdata(0xff);
                else
                    Write_uint8_tdata(0x00);
            }
        }
        delayms(1000);

        /*--------------------------------------------------*/
        /*----------------Y SCROLL---------------------------*/
        /*fill(0x00);
        setcom(0x40);
        for (yscroll = 0x00; yscroll < 0x04; yscroll++)
        {
            for (page = 0xb0; page < 0xb9; page++)
            {
                setcom(page);
                setcom(0x10);    //set Y address
                setcom(yscroll); //set Y address
                for (column = 0; column < 132; column++)
                {
                    if (column % 4 == 0)
                        Write_uint8_tdata(0xff);
                    else
                        Write_uint8_tdata(0x00);
                }
            }

            for (num = 0; num < 800; num++)
            {
                delay(125);
            }
            fill(0x00);
        }*/

        /*--------------DISPLAY IMAGE ON-------------------------*/

        setcom(0x40); /*SET INITAL LINE*/
        write_data(IMAGE0);

        for (num = 0; num < 900; num++)
        {
            delay(125);
        }
        fill(0x00);

        VDD = 1;
        VLED = 1;
    }
}

void _C13265_07_goToOrigin(void)
{
    setcom(0xaf); /*SET DISPLAY ON*/
    setcom(0x40); /*SET INITAL LINE*/
    setcom(0xb0); /*SET X ADDRESS*/
    setcom(0x10); /*SET Y ADDRESS*/
    setcom(0x00);
}

void C13265_07_full(void)
{
    fill(0x7f);
}

void C13265_07_clear(void)
{
    fill(0x00);
}

void C13265_07_img1(void)
{
    fill(0x55);
}

void C13265_07_img2(void)
{
    fill(0xaa);
}

void C13265_07_img3(void)
{
    uint8_t page, column;
    _C13265_07_goToOrigin();

    for (page = 0xb0; page < 0xb9; page++)
    {
        setcom(page);
        setcom(0x10); /*set Y address*/
        setcom(0x00); /*set Y address*/
        for (column = 0; column < 132; column++)
        {
            if (column % 2 == 0)
                Write_uint8_tdata(0xff);
            else
                Write_uint8_tdata(0x00);
        }
    }
}

void C13265_07_img4(void)
{
    uint8_t page, column;
    _C13265_07_goToOrigin();

    for (page = 0xb0; page < 0xb9; page++)
    {
        setcom(page);
        setcom(0x10); /*set Y address*/
        setcom(0x00); /*set Y address*/
        for (column = 0; column < 132; column++)
        {
            if (column % 2 == 1)
                Write_uint8_tdata(0xff);
            else
                Write_uint8_tdata(0x00);
        }
    }
}

void C13265_07_img5(void)
{

}

void C13265_07_img6(void)
{

}

void C13265_07_img7(void)
{

}

void C13265_07_img8(void)
{

}
